package com.dykj.fireFighting.web.base.bigdata.controller;

import com.dykj.fireFighting.api.base.bigdata.rcxc.entity.PatrolReportRecord;
import com.dykj.fireFighting.api.base.bigdata.rcxc.service.IPatrolReportRecordService;
import com.dykj.fireFighting.api.base.bigdata.rcxc.vo.PatrolReportRecordVo;
import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: zly
 * @Description : 日常巡查记录
 * @Date: 2021-07-12
 */
@Slf4j
@Api(value = "大数据设备统计", tags = {"大数据设备统计"})
@RestController
@RequestMapping("bigdata/patrolReportRecord")
public class BigDataPatrolReportRecordController {

    @DubboReference
    private IPatrolReportRecordService patrolReportRecordService;
    @DubboReference
    private IEnterpriseService iEnterpriseService;


    @AutoLog(value = "消防安全综合分析-日常巡查")
    @ApiOperation(value = "消防安全综合分析-日常巡查", notes = "消防安全综合分析-日常巡查")
    @GetMapping("/recordStatistics")
    public CommonResult deviceStatistics(){
        LoginUserVo user = ShiroUtil.getUser();
        //判断是类型 社会单位只看本单位  监控中心看下属单位  社会单位:0，维保单位:1，监控中心:2
        Integer enterpriseType = user.getEnterpriseType();
        HashMap<String, Object> params = new HashMap<>(16);
        if(0 == enterpriseType){
            params.put("unitId",user.getEnterpriseId().toString());
        }
        if(2 == enterpriseType){
            List<Enterprise> enterprises = iEnterpriseService.queryUnitSelect(user.getEnterpriseId().toString());
            if(enterprises.size()>0){
                params.put("enterprises",enterprises);
            }
        }
        List<PatrolReportRecordVo> list=patrolReportRecordService.reportRecordStatistics(params);

        return CommonResult.success(list) ;

    }

}
